package thread;

import java.util.Timer;
import java.util.TimerTask;

public class ThreadDemo30 {
    public static void main(String[] args) throws InterruptedException {
        Timer timer = new Timer();
        timer.schedule(new TimerTask() {
            @Override
            public void run() {
                //时间到了之后要执行的代码
                System.out.println("hello timer 3000");
            }
        },3000);
        timer.schedule(new TimerTask() {
            @Override
            public void run() {
                //时间到了之后要执行的代码
                System.out.println("hello timer 2000");
            }
        },2000);
        timer.schedule(new TimerTask() {
            @Override
            public void run() {
                //时间到了之后要执行的代码
                System.out.println("hello timer 1000");
            }
        },1000);
        System.out.println("hello main");
        Thread.sleep(5000);
        timer.cancel();//要主动结束不然Timer不知道是否其他地方还要继续添加任务
        



    }



}
